module Terms where

  import Control.Arrow
  import Data.Monoid

  data Unknown = Unknown Int
    deriving(Show, Ord, Eq)

  data Perm = Perm [(Int, Int)]
    deriving(Show, Ord)

  instance Monoid Perm where
    mempty = Perm []
    mappend (Perm l) (Perm r) = Perm $ l ++ r

  permute :: Perm -> Int -> Int
  permute (Perm []) i = i
  permute (Perm ((l, r):t)) i
    | i == l = permute (Perm t) r
    | i == r = permute (Perm t) l
    | otherwise = permute (Perm t) i

  instance Eq Perm where

  data Term = Atm Int
            | Suspend Perm Unknown
            | Abs Term Term
            | Lam Term Term
            | Restrict Term Term
            | OApp Term Term
            | TApp Term Term
            | AtmDecon Term Term Term Term
    deriving(Show, Ord)

  permutationAction :: Perm -> Term -> Term
  permutationAction perm (Atm a) =
    Atm $ permute perm a

  instance Eq Term where
